package com.example.demo.service.Impl;

import com.example.demo.entity.AttractionRecord;
import com.example.demo.mapper.AttractionRecordMapper;
import com.example.demo.service.AttractionRecordService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AttractionRecordServiceImpl implements AttractionRecordService{
    @Resource
    AttractionRecordMapper attractionRecordMapper;
    @Override
    public List<AttractionRecord> selectByAttractionId(Integer id) {
        return attractionRecordMapper.selectByAttractionId(id);
    }

    @Override
    public Integer touristExist(Integer id) {
        List<AttractionRecord> attractionRecords = attractionRecordMapper.selectByAttractionId(id);
        Integer entry = 0;
        Integer departure = 0;
        for (AttractionRecord aRecord: attractionRecords) {
            if(aRecord.getEntry() == 1){
                entry ++;
            }
            else{
                departure ++;
            }
        }
        return entry-departure;
    }
}
